package com.api.syh56.shengyunhui.mapper;

import com.api.syh56.shengyunhui.entity.Goods;
import com.api.syh56.shengyunhui.entity.Quote;
import com.api.syh56.shengyunhui.entity.Waybill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface WayBillMapper extends BaseMapper<Waybill> {

    @Select("select g.* from waybill w left outer join goods g on g.id = w.goods_id where w.id = (select id from waybill where remark = #{carType})")
    List<Goods> findGoodsByWaybillId(String carType);

    @Select("select q.* from waybill w left outer join quote q on q.waybill_id = w.id where w.id = #{wid}")
    List<Quote> findQuoteByWaybillId(Long wid);

    @Select("select w.* from waybill w " +
            "left outer join tmp_address ta on (ta.id = w.ship_address_id or ta.id = w.receive_address_id ) " +
            "where ta.city = #{place} and w.remark = #{carType} " +
            "AND w.creation_time BETWEEN #{beginLDT} AND #{endLDT} " +
            "and w.shiper_id = #{uid} ")
    Page<Waybill> findWaybillByPlaceAndCarType(Page<?> page, Long uid, LocalDateTime beginLDT, LocalDateTime endLDT, String place, String carType, Integer pageSize, Integer pageNum);


//     LIMIT #{pageSize} OFFSET (#{pageNum} - 1) * #{pageSize}
}
